package com.hq.ims.data.service;

import com.hq.ims.data.dao.LogSysExceptionMapper;
import com.hq.ims.data.entity.LogSysException;
import com.hq.ims.data.vo.LogSysExceptionMapstruct;
import com.hq.mybatis.base.BaseService;
import com.hq.mybatis.base.page.RequestPage;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * jiang bai ping
 *
 * @Email 526666031@qq.com
 * @Detail 系统异常日志服务实现类
 */
@Service
public class BaseLogSysExceptionService extends BaseService<LogSysExceptionMapper, LogSysException> {

    public List<LogSysException> getByPage(
            RequestPage page,
            LogSysExceptionMapstruct.PageSearchVo searchData
    ) {
        //根据传递的搜索参数进行检索
        this.lambdaQuery()
                .ge(searchData.getBeginTime() != null, LogSysException::getCreateDateTime, searchData.getBeginTime())
                .le(searchData.getEndTime() != null, LogSysException::getCreateDateTime, searchData.getEndTime())
                .orderByDesc(LogSysException::getCreateDateTime)
                .page(page);

        List<LogSysException> records = page.getRecords();
        return records;
    }

    /**
     * 清除日志成功
     */
    public Boolean clearLogByTime(LogSysExceptionMapstruct.ClearLogVo clearLogVo) {
        //通过日志id+时间区间清除日志
        return this.lambdaUpdate()
                .ge(clearLogVo.getBeginTime() != null, LogSysException::getCreateDateTime, clearLogVo.getBeginTime())
                .le(clearLogVo.getEndTime() != null, LogSysException::getCreateDateTime, clearLogVo.getEndTime())
                .remove();
    }
}
